package com.ajing.logextractor.extractor;

import com.ajing.logextractor.config.ExtractConfig;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public abstract class AbstractExtractor {

    String pattern;

    AbstractExtractor subExtractor;

    public AbstractExtractor(String pattern, ExtractConfig subExtractConfig) {
        this.pattern = pattern;
        this.subExtractor = ExtractorFactory.getExtractor(subExtractConfig);
    }

    abstract String extract(String input);

    public String extractDeal(String input) {
        String output = input;
        try {
            output = extract(input);
            if (null != subExtractor) {
                output = subExtractor.extractDeal(output);
            }
        } catch (Exception e) {
            log.error(String.format("extract error: [%s][%s]", pattern, e.getMessage()));
        }
        return output;
    }


}
